package tech.horgee.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import tech.horgee.common.IWrapper;
import tech.horgee.group.UpdateGroup;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 通知表
 *
 * @author haojun
 * @since 2023-12-13
 */
@Getter
@Setter
@TableName("tab_notice")
public class Notice implements Serializable, IWrapper<Notice> {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @NotNull(groups = UpdateGroup.class)
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 乐观锁
     */
    @NotNull(groups = UpdateGroup.class)
    @Version
    private Long version;

    /**
     * 逻辑删除
     */
    @TableLogic
    private Boolean deleted;

    /**
     * 创建时间
     */
    @TableField(updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime updateTime;

    /**
     * 开始时间
     */
    @TableField(exist = false)
    private LocalDateTime startTime;
    /**
     * 结束时间
     */
    @TableField(exist = false)
    private LocalDateTime endTime;


    @Override
    public LambdaQueryWrapper<Notice> wrapper() {
        return new LambdaQueryWrapper<Notice>()
                .eq(Objects.nonNull(id), Notice::getId, id)
                .like(Objects.nonNull(title), Notice::getTitle, title)
                .like(Objects.nonNull(content), Notice::getContent, content)
                .eq(Objects.nonNull(version), Notice::getVersion, version)
                .eq(Objects.nonNull(deleted), Notice::getDeleted, deleted)
                .eq(Objects.nonNull(createTime), Notice::getCreateTime, createTime)
                .eq(Objects.nonNull(updateTime), Notice::getUpdateTime, updateTime)
                .ge(Objects.nonNull(startTime), Notice::getCreateTime, startTime)
                .le(Objects.nonNull(endTime), Notice::getCreateTime, endTime)
                ;
    }
}
